/****************************************************************************************
*                                                                                      *
*                          Projeto BioInfo - Lincs and CIn / UFPE                      *
*                                    07/10/2014                                        *
*																					   *
****************************************************************************************
* Descricao: Arquivo que contem a classe Ocl.                    *
****************************************************************************************
* Responsaveis: Jefferson Ramos(jrla)													   *
*                                                                                      */
/*                                                                                     *
****************************************************************************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <malloc.h>
#include "util.hpp"

#ifdef NV //NVIDIA
	#include <oclUtils.h>
#else
	#include <CL/cl.h>
#endif


class Ocl{

	//create global variables
	int TAMSEQ = 240;
	int query_compare = 1; //query escolhida
	int run_times = 1;
	int alignment_by_individuals = 15;
	int num_individuals = 2500;
	int alignment_by_threads = 1;

	int numIndividuals_locationMaximum = 0;
	int split = 0;
	int individuals_index = 0;
	int use_gpu;

	//create cl variables
	cl_ulong buf_uint;
	cl_int err = 0;
	cl_kernel kernel1;
		

	//create buffers
	cl_mem score_vector_mem;
	cl_mem query_mem;
	cl_mem bank_mem;
	cl_mem taxa_mem;

	//create local variables
	cl_context	    context;
	cl_command_queue * cmd_queue;
	cl_device_type   device_type;
	cl_device_id   * device_list;
	cl_uint           num_devices;

public:

	double time_average = 0.0;
	double sum_time = 0.0;

	//creat vectors
	int *output_taxa;
	char *store_individuals;
	char **individuals;
	char *query;

	//creat  Files
	FILE * Results;
	FILE *BD_nucleotideos;
	FILE *TaxaOut;

	/*TypeQuery *query;

	TypeMat_direction *mat_direction;
	TypeIndividuals *individuals;
	TypeIndividuals *store_individuals;*/

	Ocl(
			int TAMSEQ,
			int alignment_by_individuals,
			int num_individuals,
			int query_compare,
			int run_time,
			int use_gpu
		);

//	**********************************************
//		Destrutor da classe Canonic
//	**********************************************
	//virtual ~Ocl();

	int shutdown();

	void usage(int argc, char **argv);

	void read_input_individuals();

	void read_input_query();

	int initializeCL(int use_gpu);

	int initializeKernel();

	int initializeCLBuffers();

	void setKernelArgs();

	int runCLKernels();

	int vectors_malloc();

	void print_results();

	void set_num_individuals(int num_individuals){
		this->num_individuals = num_individuals;
	}

	int get_num_individuals(){
		return this->num_individuals;
	}
};

